package four;

public class A064 {


    //33.搜索螺旋升序数组

    public int search(int[] nums, int target) {
        int n = nums.length;
        int left=0,right=n-1;

        while(left<=right) {
            int mid = left + (right-left)/2;
            if(nums[mid]==target) {
                return mid;
            }else if(nums[left]<=nums[mid]) {
                //[left,mid]有序
                if(target>=nums[left] && target<nums[mid]) right = mid-1;
                else left=mid+1;
            }else {//[mid+1,right]为有序
                if(nums[mid]<target && target<=nums[right]) left=mid+1;
                else right=mid-1;
            }
        }
        return -1;
    }
}
